﻿using System;
using System.IO;
using System.Web.Configuration;
using System.Web.Mvc;

using System.Collections.Generic;
using Dos.Common;
using Dos.ORM;
using Business;
using Model;
using Common;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
using Newtonsoft.Json.Linq;


namespace wxkq.Controllers
{

    public class HomeController : Controller
    {


        public ActionResult Index()
        {
            return View("login");
        }

        public ActionResult Main()
        {
            if (Session["login"] == null) {
                return Redirect("/home/Index");
            }
            return View();
        }

        public ActionResult outhome()
        {
            Session["login"] = null;
            return Redirect("/home/Index");
        }

        public ActionResult Login()
        {

            return View();
        }
        public ActionResult login_post()
        {
            string name = Assiweb.GetRequestString("name");
            string pwd = Assiweb.GetRequestString("pwd");

            string sql = " select * from yd_admin_user where username='{0}' and pwd ='{1}' ";
            sql = string.Format(sql, name, pwd);

            DataTable dt = MysqlHelper.ExecuteDataTable(sql, null);
            if (dt == null || dt.Rows.Count == 0) {
                return Json(new Jr(false, "", ""));
            }
            Session["login"] = "1";
            return Json(new Jr(true, "", ""));
        }



        


























        /// <summary>
        /// 时间戳转为C#格式时间
        /// </summary>
        /// <param name=”timeStamp”></param>
        /// <param name="bflag">为真时获取10位时间戳,为假时获取13位时间戳.</param>
        /// <returns></returns>
        private DateTime GetTime(string timeStamp, bool bflag = true)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime;
            if (bflag == true)
            {
                lTime = long.Parse(timeStamp + "0000000");
            }
            else
            {
                lTime = long.Parse(timeStamp + "0000");
            }

            TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow);
        }
        /// <summary>  
        /// 获取当前时间戳  
        /// </summary>  
        /// <param name="bflag">为真时获取10位时间戳,为假时获取13位时间戳.</param>  
        /// <returns></returns>  
        public static string GetTimeStamp(bool bflag = true)
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string ret = string.Empty;
            if (bflag)
                ret = Convert.ToInt64(ts.TotalSeconds).ToString();
            else
                ret = Convert.ToInt64(ts.TotalMilliseconds).ToString();

            return ret;
        }
 

        

    }
}